
package com.example.cia.service;

import com.example.cia.support.HttpService;

public class addDeviceService implements Service{
	
	boolean flag;

	@Override
	public void setFlag(boolean b) {
		flag = b;
	}
	
	public addDeviceService(){
		flag = false;
	}
	
	/**
	 * add device info to database
	 * @param id the identifier of this device
	 * @param description the detailed description of this device
	 * @param status describes the status of this device
	 * @return true if successful added,otherwise false
	 */
	public boolean addDevice(String id, String description,int state){
		String result;
		HttpService<String> addDevice = new HttpService<String>();
		addDevice.setUrl("/CIADatabse/addDeviceServlet");
		addDevice.doHttpGet("id="+id+"&description="+description+"&state="+state);
		addDevice.setService(this);
		while(true){
			if(!flag);
			else
				break;
		}
		result = addDevice.getResult();
		//执行成功后MySQL返回影响行数，为1表示成功，为0表示失败
		if(result.matches("true"))
			return true;
		return false;
	}
	
}
